package com.push.notifications;

import java.util.List;

import android.content.Context;

public class databaseWrapper {

	public static DatabaseHelper database=null;
	public static void checkCreateDatabase(Context mContext)
	{
		if(database == null)
        {
        	database=new DatabaseHelper(mContext);
        } 
	}
	
	public static List<categoryItem> getListCategoryById(Context context,int nId)
	{
		checkCreateDatabase(context);
		if(database != null)
		{
			return database.getAllCategoryByParentId(nId);
		}
		return null;
	}
	
	
	public static void insertNews(Context context,int idCategory,String subTitle,String title,String thumb,int idContent)
	{
		
		checkCreateDatabase(context);
		if(database != null)
		{
			database.InsertNews(idCategory, subTitle,title,thumb,idContent);
		}
	}
	public static int getLastestNews(Context context)
	{
		checkCreateDatabase(context);
		if(database != null)
		{
			return database.getLastestNews();
		}
		return -1;
	}
	public static categoryItem getCategory(Context context,int nIdCategory, int nParentId)
	{
		checkCreateDatabase(context);
		if(database != null)
		{
			return database.getCategory(nIdCategory,nParentId);
		}
		return null;
	}
	
	public static  void insertCategory(Context context,categoryItem item)
	{
		checkCreateDatabase(context);
		if(database != null && item != null)
		{
			int status = 0;
			 if(item.isSelected())
				 status = 1;
			database.InsertCatagory(item.getName(), item.getCategory(), item.getParentId(),
					item.getCommand(),item.s_image,status,item.getDesc());
		}
		
	}
	
	public static void deleteAllCategoryHaveParentId(Context context,int parentId)
	{
		checkCreateDatabase(context);
		if(database != null )
		{
			database.deleteDatainCategory(parentId);
		}
	}
	
	public static void updateCategory(Context context,int nIdCategory, int nParentId,int nStatus)
	{
		checkCreateDatabase(context);
		if(database != null )
		{
			database.updateStatusCategory( nIdCategory, nParentId,nStatus);
		
		}
	}
	
	public static List<historyItem> getNewsByCategory(Context context,int Categoryid)
	{
		checkCreateDatabase(context);
		if(database != null )
		{
			return database.getNewsByCategory(Categoryid);
		}
		return null;
	}
	
	public static List<historyItem> getMessageById(Context context,int Categoryid)
	{
		checkCreateDatabase(context);
		if(database != null )
		{
			return database.getMessagebyID(Categoryid);
		}
		return null;
	}
	
	public static List<categoryItem> getListSubNews(Context context,int Categoryid)
	{
		checkCreateDatabase(context);
		if(database != null )
		{
			return database.getListSubNewsHistory(Categoryid);
		}
		return null;
	}
	
	public static int updateExpression(Context context,int nCategoryId,String link,String content)
	{
		checkCreateDatabase(context);
		if(database != null )
		{
			return database.updateExpressionById(nCategoryId, link, content);
		}
		return -1;
	}
	
	public static String getLinkInExpressById(Context context,int categoryId)
	{
		checkCreateDatabase(context);
		if(database != null )
		{
			return database.getLinkInExpressById(categoryId);
		}
		return "";
	}
}
